package cn.seaboot.excel.sax;

import org.dom4j.Element;

import java.io.IOException;
import java.util.List;

/**
 * parse tag: tr
 *
 * @author Mr.css
 * @version 2025-07-01 14:37
 */
public class TableRowParser implements DocumentParser {

    /**
     * 要操作的 excel 上下文
     */
    private ExcelContext context;

    /**
     * 单元格解析器
     */
    private DocumentParser tableCellParser = new TableCellParser();

    public ExcelContext getContext() {
        return context;
    }

    public void setContext(ExcelContext context) {
        this.context = context;
        this.tableCellParser.setContext(context);
    }

    public DocumentParser getTableCellParser() {
        return tableCellParser;
    }

    public void setTableCellParser(DocumentParser tableCellParser) {
        this.tableCellParser = tableCellParser;
    }

    @Override
    public void parse(Element tr) throws IOException {
        // next line
        context.nextLine();

        // 处理单元格内的数据
        List<Element> cells = tr.elements();
        for (Element cell : cells) {
            tableCellParser.parse(cell);
        }
    }
}
